package com.example.q_kang.hhh.home;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.q_kang.hhh.R;
import com.hjq.toast.ToastUtils;
import com.sskj.base.MVPActivity;
import com.sskj.base.base.App;
import com.sskj.base.bean.HomeCommonBean;
import com.sskj.base.utils.CheckUtil;
import com.sskj.base.utils.ClickUtil;
import com.sskj.base.view.ToolBarLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/04/10
 */
public class CoinPindanSendActivity extends MVPActivity<CoinPindanSendPresenter> {


    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.tv_total_account)
    TextView tvTotalAccount;
    @BindView(R.id.et_mobile)
    EditText etMobile;
    @BindView(R.id.et_amount)
    EditText etAmount;
    @BindView(R.id.btn_submit)
    Button btnSubmit;
    @BindView(R.id.btn_create_coin)
    Button btnCreateCoin;

    @Override
    public int getLayoutId() {
        return R.layout.activity_coin_pinda_nsend;
    }

    @Override
    public CoinPindanSendPresenter getPresenter() {
        return new CoinPindanSendPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(view -> finish());
        toolbar.setRightButtonOnClickListener(view -> SendRecordActivity.start(this, App.INSTANCE.getString(R.string.appJavaCoinPindanSendActivity1)));
        ClickUtil.click(300, btnCreateCoin, view -> CreateCoinActivity.start(this));
        ClickUtil.click(300, btnSubmit, view -> {
            if (TextUtils.isEmpty(getEtext(etMobile))) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaCoinPindanSendActivity2));
                return;
            }
            if (!CheckUtil.isMobile(getEtext(etMobile))) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaCoinPindanSendActivity3));
                return;
            }
            if (TextUtils.isEmpty(getEtext(etAmount))) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaCoinPindanSendActivity4));
                return;
            }
            mPresenter.sendPaiDan(getEtext(etMobile), getEtext(etAmount));
        });
    }

    @Override
    public void initData() {
        mPresenter.getMyCoin();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        mPresenter.getMyCoin();
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, CoinPindanSendActivity.class);
        context.startActivity(intent);
    }

    public void getMyCoinSuccess(HomeCommonBean.UserMoneyBean userMoney) {
        tvTotalAccount.setText(userMoney.getFour());
    }
}
